<html><head><title>ReadFile</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<font face="Arial" size="2"><p align="center"><b><font size="4">ReadFile()</font></b></p>
<p><b>Syntax</b></p><blockquote>
Result = <font color="#006666"><b>ReadFile</b></font>(#File, Filename$ [, Flags])</blockquote>

</blockquote>
<b>Description</b><br><blockquote>

Open an existing file for read-only operations. 

</blockquote><p><b>Parameters</b></p><blockquote>
<style type="text/css">
table.parameters { border-spacing: 0px; border-style: none; border-collapse: collapse; }
table.parameters td { border-width: 1px; padding: 6px; border-style: solid; border-color: gray; vertical-align: top; font-family:Arial; font-size:10pt; }
</style>
<table width="90%" class="parameters">
<tr><td width="10%"><i>#File</i></td>
<td width="90%"> 
The number to identify the file. <a href="../reference/purebasic_objects.html">#PB_Any</a> can be used to 
auto-generate this number. 

</td></tr>
<tr><td><i>Filename$</i></td>
<td> 
The filename and path to the file. If the filename does not include a full path, it 
is interpreted relative to the <a href="../filesystem/getcurrentdirectory.html">current directory</a>. 

</td></tr>
<tr><td><i>Flags (optional)</i></td>
<td> 
It can be a combination (using the '| operand) of the following values: 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_File_SharedRead</font> : the opened file can be read by another process (Windows only).
  <font color="#924B72">#PB_File_NoBuffering</font>: the internal PureBasic file buffering system will be disabled for this file. 
                        <a href="filebufferssize.html">FileBuffersSize()</a> can not be used on this file.
</font></pre>

</td></tr>
</table>
</blockquote><p><b>Return value</b></p><blockquote>

Returns nonzero if the file was opened successfully and zero if there was an error. 
If <font color="#924B72">#PB_Any</font> was used as the #File parameter then the new generated number is returned on success. 

</blockquote><p><b>Remarks</b></p><blockquote>

To open a file for reading and writing, use the <a href="openfile.html">OpenFile()</a> function. 
To create a new and empty file, use the <a href="createfile.html">CreateFile()</a> function. 

</blockquote><p><b>Example</b></p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">
  <b><font color="#006666">If</font></b> <font color="#006666">ReadFile</font>(0, "Text.txt")   <font color="#006666">; if the file could be read, we continue...</font>
    <b><font color="#006666">While</font></b> <font color="#006666">Eof</font>(0) = 0           <font color="#006666">; loop as long the 'end of file' isn't reached</font>
      <b><font color="#006666">Debug</font></b> <font color="#006666">ReadString</font>(0)      <font color="#006666">; display line by line in the debug window</font>
    <b><font color="#006666">Wend</font></b>
<font color="#006666">    CloseFile</font>(0)               <font color="#006666">; close the previously opened file</font>
  <b><font color="#006666">Else</font></b>
<font color="#006666">    MessageRequester</font>("Information","Couldn't open the file!")
  <b><font color="#006666">EndIf</font></b>

</font></pre>

</blockquote><p><b>See Also</b></p><blockquote>

<a href="openfile.html">OpenFile()</a>, <a href="createfile.html">CreateFile()</a>, <a href="closefile.html">CloseFile()</a> 

</Blockquote><p><b>Supported OS </b><Blockquote>All</Blockquote></p><center><- <a href=readdouble.html>ReadDouble()</a> - <a href=index.html>File Index</a> - <a href=readfloat.html>ReadFloat()</a> ->

</body></html>